package view.controller;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import logic.FileSystem;
import logic.MyFile;
import view.newFileWindow;

public class NewFolderWindowController {
    public void NewFolderWindowController(){}
    static FileSystem fileSystem;

    public static FileSystem getFileSystem() {
        return fileSystem;
    }

    public Button getSubmit() {
        return submit;
    }

    @FXML
    public TextField foldername;

    @FXML
    public Button submit;

    public TextField getFoldername() {
        return foldername;
    }

    public void initialize(){
        //System.out.println("newFileWindow init");
        fileSystem = FileSystem.getInstance();
    }

    public static void submit(NewFileWindowController controller, DiskController diskController){
        //System.out.println("submit");
        String name = controller.getFilename().getText();
        String type = controller.getFiletype().getText();
        boolean flag = fileSystem.nameValidityTest(name,type).isRes();
        //System.out.println(flag);
        if(flag){
            //todo 添加到list
            int attr = controller.getRead().isSelected()?1:4;
            MyFile myFile = (MyFile) fileSystem.createFile(name,type,attr).getObj();
            Button bu = new Button();
            ImageView img = new ImageView(newFileWindow.class.getClassLoader().getResource("File.jpg").toString());
            img.setFitHeight(70);
            img.setFitWidth(70);
            bu.setPrefSize(70,70);
            bu.setGraphic(img);
            diskController.map.put(bu,myFile);
            diskController.flush();
        }
    }
}
